package com.bocweb.fly.jiaodao.fragment;


import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.widget.Toolbar;
import android.widget.TextView;
import android.widget.Toast;

import com.bocweb.fly.jiaodao.R;
import com.bocweb.fly.jiaodao.utils.CircularImage;
import com.bocweb.fly.jiaodao.utils.SegmentControl;
import com.bumptech.glide.Glide;
import com.milk.base.BaseFragment;

import butterknife.Bind;

/**
 * Created by fly on 16/10/10.
 */
public class FmBusiness extends BaseFragment {
    @Bind(R.id.segment_control)
    SegmentControl mSegmentControl;
    private Fragment mTab01;
    private Fragment mTab02;

    @Override
    protected int getLayoutId() {
        return R.layout.fragment_business;
    }

    @Override
    protected boolean flux() {
        return false;
    }

    @Override
    public void initData() {
        setSelect(0);
        mSegmentControl.setOnSegmentControlClickListener(new SegmentControl.OnSegmentControlClickListener() {
            @Override
            public void onSegmentControlClick(int index) {
                switch (index) {
                    case 0:
                        setSelect(0);
                        break;
                    case 1:
                        setSelect(1);
                        break;
                }
            }
        });
    }

    private void setSelect(int i) {
        FragmentManager fm = getChildFragmentManager();
        FragmentTransaction transaction = fm.beginTransaction();
        hideFragment(transaction);
        switch (i) {
            case 0:
                if (mTab01 == null) {
                    mTab01 = new FmMyBusiness();
                    transaction.add(R.id.id_contents, mTab01);
                } else {
                    transaction.show(mTab01);
                }
                break;
            case 1:
                if (mTab02 == null) {
                    mTab02 = new FmMyBusiness();
                    transaction.add(R.id.id_contents, mTab02);
                } else {
                    transaction.show(mTab02);
                }
                break;
        }
        transaction.commitAllowingStateLoss();
    }

    private void hideFragment(FragmentTransaction transaction) {
        if (mTab01 != null) {
            transaction.hide(mTab01);
        }
        if (mTab02 != null) {
            transaction.hide(mTab02);
        }
    }
}

